package com.htht.smartschool.service.schoolbus;

import java.util.ArrayList;
import java.util.List;

import com.htht.smartschool.common.service.BaseService;
import com.htht.smartschool.model.schoolbus.TBus;
import com.htht.smartschool.model.schoolbus.TLine;
import com.htht.smartschool.model.schoolbus.TDriver;
import com.htht.smartschool.model.schoolbus.TBuswarn;


public class SchoolBusService extends BaseService{
	@SuppressWarnings("unchecked")
	public List<TLine> getSchoolBusLineInfo(TLine tline) {
		String sql = "select id,linecode,astext(stopstation) as stopstation,gostoptime,backstoptime,remark,astext(linepoints) as linepoints from t_line";
		List<TLine> list = new ArrayList<TLine>();
		List<Object[]> res = getDao().queryBySQL(sql);
		for(int i = 0; i < res.size(); i++){
			Object[] obj = res.get(i);
			TLine line = new TLine();
			
			line.setLinecode(String.valueOf(obj[1]));
			line.setStopstation(String.valueOf(obj[2]));
			line.setGostoptime(Long.valueOf(String.valueOf(obj[3])));
			line.setBackstoptime(Long.valueOf(String.valueOf(obj[4])));
			line.setRemark(String.valueOf(obj[5]));
			line.setLinepoints(String.valueOf(obj[6]));
			
			list.add(line);
		}
		return list;
	}
	@SuppressWarnings("unchecked")
	public List<TBus> getSchoolBusInfo(TBus tbus) {
		String hql = String.format("from TBus");
		List<TBus> list = getDao().queryByHQL(hql,tbus);
		return list;
	}
	
	public TBus addSchoolBus(TBus tbus){
		return (TBus) getDao().create(tbus);
	}
	
	public TBus updateSchoolBus(TBus tbus){
		return (TBus) getDao().update(tbus);
	}
	
	public boolean deleteSchoolBus(TBus tbus){
		return getDao().delete(tbus);
	}
	
	@SuppressWarnings("unchecked")
	public List<TDriver> getSchoolBusDriverInfo(TDriver tdriver) {
		String hql = String.format("from TDriver");
		List<TDriver> list = getDao().queryByHQL(hql,tdriver);
		return list;
	}
	
	public TDriver addSchoolBusDriver(TDriver tdriver){
		return (TDriver) getDao().create(tdriver);
	}
	
	public TDriver updateSchoolBusDriver(TDriver tdriver){
		return (TDriver) getDao().update(tdriver);
	}
	
	public boolean deleteSchoolBusDriver(TDriver tdriver){
		return getDao().delete(tdriver);
	}
	
	@SuppressWarnings("unchecked")
	public List<TBuswarn> getSchoolBuswarnInfo(TBuswarn tbuswarn) {
		String hql = String.format("from TBuswarn");
		List<TBuswarn> list = getDao().queryByHQL(hql,tbuswarn);
		return list;
	}
	
	public TBuswarn addSchoolBuswarn(TBuswarn tbuswarn){
		return (TBuswarn) getDao().create(tbuswarn);
	}
	
	public TBuswarn updateSchoolBuswarn(TBuswarn tbuswarn){
		return (TBuswarn) getDao().update(tbuswarn);
	}
	
	public boolean deleteSchoolBuswarn(TBuswarn tbuswarn){
		return getDao().delete(tbuswarn);
	}
}
